/**
 * 存储工具类
 */
// 存储数据到 LocalStorage
export function setLocalStorage(key, data) {
  try {
    localStorage.setItem(key, JSON.stringify(data))
  } catch (error) {
    console.error('setLocalStorage: ', error)
  }
}

// 从 LocalStorage 获取数据
export function getLocalStorage(key) {
  let data
  try {
    const str = localStorage.getItem(key)
    if (str) {
      data = JSON.parse(str)
      return data
    }
  } catch (error) {
    console.error('getLocalStorage: ', error)
  }
}

// 存储数据到 SessionStorage
export function setSessionStorage(key, data) {
  try {
    sessionStorage.setItem(key, JSON.stringify(data))
  } catch (error) {
    console.error('setSessionStorage: ', error)
  }
}

// 从 SessionStorage 获取数据
export function getSessionStorage(key) {
  let data
  try {
    const str = sessionStorage.getItem(key)
    if (str) {
      data = JSON.parse(str)
      return data
    }
  } catch (error) {
    console.error('getSessionStorage: ', error)
  }
}
